package canvas;






import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

import objetos.CanvasGame;
import objetos.GamePanel;
import objetos.myCanvas;

public class CanvasMenuPause extends myCanvas{

	public static CanvasMenuPause instance = null;


	BufferedImage menuImage;

	BufferedImage resumeOnImg;
	BufferedImage loadOnImg;
	BufferedImage quitOnImg;
	
	BufferedImage menugameOn;
	


	long timerCompra, timerVenda;

	boolean mouseOverEasy = false;
	boolean mouseOverMedium = false;
	boolean mouseOverHard = false;

	Random rnd = new Random();

	long diftime, timerCLick;

	public CanvasMenuPause() {
		
		menuImage = GamePanel.loadImage("./../bgBack.png");   // imagem de fundo arvores

		
		menugameOn = GamePanel.loadImage("./../menuPause.png");
		
		resumeOnImg =  GamePanel.loadImage("./../resumeGameOn.png");

		
		loadOnImg =  GamePanel.loadImage("./../loadGameOn.png");
		
		
		quitOnImg =  GamePanel.loadImage("./../quitGameOn.png");
		
		
		instance = this;		


	}

	@Override
	public void SimulaSe(long diftime) {
		this.diftime = diftime;
		//System.out.print("\n MAPA ATUAL DO SHOP => " + CanvasGame.MapaAtual+ "\n");
		timerCLick += this.diftime;
		checaMouseLoja();

	}

	private void checaMouseLoja() {


	    // RESUME game
		if(CanvasGame.instance.MouseX > 237 && CanvasGame.instance.MouseX < 402 && CanvasGame.instance.MouseY > 131 && CanvasGame.instance.MouseY < 166){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;

				GamePanel.canvasAtivo = CanvasGame.instance; 
				
			}
			
		}

		// load
		if(CanvasGame.instance.MouseX > 237 && CanvasGame.instance.MouseX < 402 && CanvasGame.instance.MouseY > 165 && CanvasGame.instance.MouseY < 217){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;
				
				// COLOCAR LOAD DO JOGO E JOGAR DIRETO

				GamePanel.canvasAtivo = CanvasMenuPrincipal.instance;
			}
			
		}

	    // QUIT GAME
		if(CanvasGame.instance.MouseX > 237 && CanvasGame.instance.MouseX < 402 && CanvasGame.instance.MouseY > 232 && CanvasGame.instance.MouseY < 267){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;
				
			    GamePanel.instance.running = false; // exit de game
			}
		}
		
		

	}

	public void DesenhaSe(Graphics2D dbg) {


		dbg.drawImage(menuImage, 0, 0, null); // tamanho da imagem


		dbg.drawImage(menugameOn, GamePanel.WIDTH/2+328/2, GamePanel.PHEIGHT/2-354/2, null); // tamanho da imagem

		dbg.setColor(Color.RED);
		
		
		
		// mapeamento
		//dbg.drawRect(237, 131, 165, 35);  // new game
		//dbg.drawRect(237, 182, 165, 35);  // load
		//dbg.drawRect(237, 232, 165, 35);  // exit
		
		
		
		
		if(mouseOverEasy){
			//dbg.drawImage(resumeOnImg, 268, 193, null);
		}
		//dbg.drawRect(268, 238, 122, 35);  //mapeamento link +45 em y medium
		if(mouseOverMedium){
			//dbg.drawImage(optionsOnImg, 268, 238, null);
		}

		//dbg.drawRect(268, 283, 122, 35);  //mapeamento link + 90 em y hard
		if(mouseOverHard){
			//dbg.drawImage(hardOn, 268, 283, null);
		}


	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();


		//CanvasGame.instance.dinheiro = 0;

		//CanvasGame.instance.listadePetdoveiculo.clear();
		//CanvasGame.instance.listadePetSystem.clear();

		//if (keyCode == KeyEvent.VK_ENTER) {
		//	GamePanel.canvasAtivo = CanvasGame.instance;	
		//}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		//System.out.print("MOVEU O MOUSEEEEEEEEEEEEE ");


	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//System.out.print("Clicou AEEEEEEEEEEEEEEH ");
		CanvasGame.instance.MouseX = e.getX();
		CanvasGame.instance.MouseY = e.getY();
		int cont = 0;

	}

	public static BufferedImage loadImage(String source) {
		BufferedImage image = null;
		try {
			BufferedImage tmp = ImageIO.read(CanvasGame.instance.getClass()
					.getResource(source));
			image = new BufferedImage(tmp.getWidth(), tmp.getHeight(),
					BufferedImage.TYPE_INT_ARGB);
			image.getGraphics().drawImage(tmp, 0, 0, null);
			tmp = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.print("CLICOU NO MOUSE AEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEH");

	}



}
